package edu.bw.service.Impl;

import edu.bw.config.SpringConfig;
import edu.bw.po.Product;
import edu.bw.service.ProductService;
import edu.bw.utils.TransactionProxyFactory;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;

import static org.junit.jupiter.api.Assertions.*;

@SpringJUnitConfig(SpringConfig.class)
public class ProductServiceImplTest03 {


    @Autowired
    private TransactionProxyFactory transactionProxyFactory;

    /**
     * 为有接口的类生成代理类
     */
    @Test
    public void test01(){
        ProductService proxyInstance =(ProductService) transactionProxyFactory
                .createProxyInstance(ProductServiceImpl.class);
        proxyInstance.updateProduct(new Product(13,"单反索尼相机",199,"数码相机"));

        proxyInstance.findAll().forEach(System.out::println);

    }
    /**
     * 为没有接口的类生成代理类
     */
    @Test
    public void test02(){
        ProductServiceImpl02 proxyInstance =(ProductServiceImpl02) transactionProxyFactory
                .createProxyInstance(ProductServiceImpl02.class);
        proxyInstance.updateProduct(new Product(13,"单反索尼相机",5999,"数码相机"));

        proxyInstance.findAll().forEach(System.out::println);

    }



}